/*
*编写程序统计长度不小于4的单词，并输出输入序列中不重复的单词。在程序源文件上运行和测试你自己编写的程序
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <string>
using namespace std;

bool GT4(string &);

int main()
{
	vector<string> words;
	words.push_back("the");
	words.push_back("quick");
	words.push_back("red");
	words.push_back("fox");
	words.push_back("jumps");
	words.push_back("over");
	words.push_back("the");
	words.push_back("slow");
	words.push_back("red");
	words.push_back("turtle");

	cout <<  "长度不小于4的单词的个数为：" << count_if(words.begin(),words.end(),GT4) << endl;

	cout << "序列中不重复的单词：" << endl;
	//将单词按字典顺序排序
	sort(words.begin(),words.end());
	//去重
	vector<string>::iterator end_unique = unique(words.begin(),words.end());
	words.erase(end_unique,words.end());
	//遍历输出
	vector<string>::iterator allit = words.begin();
	while(allit != words.end())
	{
		cout << *allit << "  ";
		++allit;
	}

	cout << endl;
	system("pause");
    return 0;
}

bool GT4(string &str)
{
	return str.size() >= 4;
}

